package com.hao.DaoImpl;

import com.hao.Dao.staffDao;
import com.hao.Dao.userDao;
import com.hao.entity.staff;

import com.hao.util.BaseDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/8/11.
 */
        public class staffImpl implements staffDao {
    @Override
    public List<staff> findstaff(int sid) {
        List<staff> list=new ArrayList<staff>();
        String sql="SELECT * FROM staff where 1=1 ";
        if (sid!=-1) {
            sql+=" and staffid=?";
        }
        Connection conn=null;
        PreparedStatement state=null;
        ResultSet rs=null;
        try {
            conn= BaseDao.getConnection();
            state=conn.prepareStatement(sql);
            if(sid!=-1) {
                state.setInt(1, sid);
            }
            rs=state.executeQuery();
            userDao dao=new userImpl();
            while(rs.next()){
                staff oo=new staff();
                oo.setStaffid(rs.getInt("staffid"));
                oo.setUserid(rs.getInt("userid"));
                oo.setUlist(dao.finduser(rs.getInt("userid")));
                list.add(oo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            BaseDao.closeConnection(conn, state, rs);
        }
        return list;
    }
}
